package edu.bbu.license.client.android.communication.utils;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

import edu.bbu.license.client.android.communication.services.thrift.ThriftService;


/**
 * The thrift executor class.
 */
public class ThriftExecutor
{
	/** Client transport. */
	private TTransport clientTransport;
	
	/** The client. */
	private ThriftService.Client client;
	
	/**
	 * The constructor.
	 * @param hostAdress the host address.
	 * @param port the host port.
	 */
	public ThriftExecutor(String hostAdress, int port)
	{
		clientTransport = new TSocket(hostAdress, port, 10000);
		client = new ThriftService.Client(new TBinaryProtocol(clientTransport));
	}
	
	/**
	 * It opens the client transport.
	 * @throws TTransportException if open was onsuccesfull.
	 */
	public void open() throws TTransportException
	{
		clientTransport.open();
	}
	
	/**
	 * It closes the client transport.
	 */
	public void close()
	{
		clientTransport.close();
	}
	
	/**
	 * It return the client.
	 * @return the client.
	 */
	public ThriftService.Client getExecutor()
	{
		return client;
	}
}
